home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / html / Map$RectangleRegionContainment.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  1.5 KB  |  66 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.awt.Rectangle;
  4. import javax.swing.text.AttributeSet;
  5. import javax.swing.text.html.HTML.Attribute;
  6.  
  7. class Map$RectangleRegionContainment extends Rectangle implements Map.RegionContainment {
  8.    float[] percents;
  9.    int lastWidth;
  10.    int lastHeight;
  11.  
  12.    public Map$RectangleRegionContainment(AttributeSet var1) {
  13.       int[] var2 = Map.extractCoords(var1.getAttribute(Attribute.COORDS));
  14.       this.percents = null;
  15.       if (var2 != null && var2.length == 4) {
  16.          super.x = var2[0];
  17.          super.y = var2[1];
  18.          super.width = var2[2];
  19.          super.height = var2[3];
  20.          if (super.x < 0 || super.y < 0 || super.width < 0 || super.height < 0) {
  21.             this.percents = new float[4];
  22.             this.lastWidth = this.lastHeight = -1;
  23.  
  24.             for(int var3 = 0; var3 < 4; ++var3) {
  25.                if (var2[var3] < 0) {
  26.                   this.percents[var3] = (float)Math.abs(var2[var3]) / 100.0F;
  27.                } else {
  28.                   this.percents[var3] = -1.0F;
  29.                }
  30.             }
  31.          }
  32.  
  33.       } else {
  34.          throw new RuntimeException("Unable to parse rectangular area");
  35.       }
  36.    }
  37.  
  38.    public boolean contains(int var1, int var2, int var3, int var4) {
  39.       if (this.percents == null) {
  40.          return ((Rectangle)this).contains(var1, var2);
  41.       } else {
  42.          if (this.lastWidth != var3 || this.lastHeight != var4) {
  43.             this.lastWidth = var3;
  44.             this.lastHeight = var4;
  45.             if (this.percents[0] != -1.0F) {
  46.                super.x = (int)(this.percents[0] * (float)var3);
  47.             }
  48.  
  49.             if (this.percents[1] != -1.0F) {
  50.                super.y = (int)(this.percents[1] * (float)var4);
  51.             }
  52.  
  53.             if (this.percents[2] != -1.0F) {
  54.                super.width = (int)(this.percents[2] * (float)var3);
  55.             }
  56.  
  57.             if (this.percents[3] != -1.0F) {
  58.                super.height = (int)(this.percents[3] * (float)var4);
  59.             }
  60.          }
  61.  
  62.          return ((Rectangle)this).contains(var1, var2);
  63.       }
  64.    }
  65. }
  66.